package com.asia5b.a5mall.member.adapter

import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import com.asia5b.a5mall.member.R
import com.asia5b.a5mall.member.databinding.ItemMineOrderAdapterBinding
import com.asia5b.a5mall.middleware.config.UserRepository
import com.asia5b.a5mall.middleware.model.bean.MineItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2019/12/21.
 */
class MineItemAdapter(list: ArrayList<MineItemBean>) :
        BaseQuickAdapter<MineItemBean, BaseDataBindingHolder<ItemMineOrderAdapterBinding>>(R.layout.item_mine_order_adapter, list) {

    override fun convert(helper: BaseDataBindingHolder<ItemMineOrderAdapterBinding>, item: MineItemBean) {
        helper.setIsRecyclable(false)
        val viewDataBindingTag = helper.dataBinding!!
        viewDataBindingTag.mineItemBean = item
        helper.itemView.setOnClickListener {
            item.onClickListener?.onClick(it)
        }
        val tv_difforder_count = helper.getView<TextView>(R.id.tv_difforder_count)
        if (item.other != null && (item.other!! is Int)) {
            UserRepository.setNums(tv_difforder_count, item.other.toString().toInt())
        }
        helper.getView<ImageView>(R.id.iv_mine_scan).setImageResource(item.iconRes)
    }
}